﻿using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn;
using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PMAF.K3cloud.SCM.Convert.ServicePlugIn
{
    [HotUpdate]
    [Description("销售订单转销售出库单插件")]
    public class SaleOrderToOutStock : AbstractConvertPlugIn
    {


        public override void AfterConvert(AfterConvertEventArgs e)
        {
            ExtendedDataEntity[] extendedDataEntities = e.Result.FindByEntityKey("FBillHead");
            foreach (ExtendedDataEntity targetEntity in extendedDataEntities)
            {
                DynamicObject dynamicObject = targetEntity.DataEntity as DynamicObject;
                //DynamicObjectCollection dynamicObjectCollection = dynamicObject["PMAF_OutStockPurchaseSn"] as DynamicObjectCollection;
            }
            //找到目标单单据关联主实体
            var targetForm = e.TargetBusinessInfo.GetForm();
            //if (targetForm.LinkSet == null 
            //    || targetForm.LinkSet.LinkEntitys == null 
            //    || targetForm.LinkSet.LinkEntitys.Count == 0)
            //{
            //    //目标单未设置关联主实体，无法获取目标单的源单信息，携带不了
            //    return;
            //}

            //关联主实体
            

            Entity entity = e.TargetBusinessInfo.GetEntity(targetForm.LinkSet.LinkEntitys[0].ParentEntityKey);
            Entity linkEntity = e.TargetBusinessInfo.GetEntity(targetForm.LinkSet.LinkEntitys[0].Key);

        }

        public override void OnFieldMapping(FieldMappingEventArgs e)
        {
            object convertSource = e.ConvertSource;
        }

        public override void OnQueryBuilderParemeter(QueryBuilderParemeterEventArgs e)
        {
            
        }
    }
}
